package org.fuyd.designpattern;

import java.util.Calendar;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * Hello world!
 */
public class App {

    public static AtomicInteger atomicInteger;

    static {
        Calendar calendar = Calendar.getInstance();
        int i = calendar.get(Calendar.MILLISECOND);
        atomicInteger = new AtomicInteger(i);
    }

    /**
     * 获取int类型的值
     *
     * @return
     */
    private static synchronized int getId() {
        if (atomicInteger.get() > 1024) {
            atomicInteger.set(0);
        }

        int value = atomicInteger.getAndIncrement();
        return value;
    }

    /**
     * 字典
     */
    private static String[] chars = new String[]{
            "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
            "A", "B", "C", "D", "E", "F", "G",
            "H", "I", "J", "K", "L", "M", "N",
            "O", "P", "Q", "R", "S", "T",
            "U", "V", "W", "X", "Y", "Z"
    };

    public static void main(String[] args) {
        //0 & 0 = 0, 0 & 1 = 0, 1 & 0 = 0, 1 & 1 = 1。
        //System.out.println(ten2two(getTimeStamp()));
        //1010110001010001101001001010011  长度31
        //System.out.println(sixteen2two(0x7FFFFFFF));
        //1111111111111111111111111111111  长度31

//        System.out.println(getTimeStamp());
//        Long idx = 0xFFFFFFFF & getTimeStamp();
//        System.out.println(idx);
//        System.out.println(ten2two(1445516751));
//        System.out.println(0x1F & 1445516751);

        long l = 1445516751;
        String out = "";
        for (int k = 0; k < 7; k ++) {
            long i = 0x1F & l;
            out += chars[new Long(i).intValue()];
            l = l >> 5;
        }
        System.out.println(out);

        int x = getId();
        System.out.println(x);
        out += chars[0x1F & x];
        x = x >> 5;
        out += chars[0x1F & x];
        System.out.println(out);

    }

    public static long getTimeStamp() {
        return System.currentTimeMillis()/1000;
    }

    /**
     * 十进制转二进制
     * @param i
     * @return
     */
    public static String ten2two (int i) {
        return Integer.toBinaryString(i);
    }

    /**
     * 二进制转十进制
     * @param str
     * @return
     */
    public static int two2teni(String str) {
        return Integer.valueOf(str, 2);
    }

    /**
     * 十进制转二进制
     * @param l
     * @return
     */
    public static String ten2two (long l) {
        return Long.toBinaryString(l);
    }

    /**
     * 二进制转十进制
     * @param str
     * @return
     */
    public static long two2tenl(String str) {
        return Long.valueOf(str, 2);
    }

    /**
     * 十六进制转二进制
     * @param l
     * @return
     */
    public static String sixteen2two(long l) {
        return Long.toBinaryString(l);
    }

    /**
     * 十六进制转二进制
     * @param i
     * @return
     */
    public static String sixteen2two(int i) {
        return Integer.toBinaryString(i);
    }

    public static long getLong(String str){
        str = "FELH2B17B";


        return 1;
    }

}
